#include "SpecialProxyModel.h"



#include <ItemModel.h>



namespace
{
QString SPECIAL_GROUP_ID = ".Special";
}



SpecialProxyModel::SpecialProxyModel(QObject *parent) :
    AbstractTreeProxyModel(parent)
{
}



int SpecialProxyModel::columnCount(const QModelIndex &parent) const
{
    Q_UNUSED(parent);
    return (Field_LAST - Field_FIRST + 1);
}



QVariant SpecialProxyModel::headerData(int section, Qt::Orientation orientation, int role) const
{
    Q_UNUSED(orientation);
    if (role != Qt::DisplayRole) return QVariant();

    switch (section)
    {
    case NameField: return tr("Special Power");
    }

    return QVariant();
}



void SpecialProxyModel::remap()
{
    ItemModel* model = itemModel();
    if (!model) return;

    QModelIndex sourceGroup = model->index(0, AbstractItem::IdData, QModelIndex());
    while (sourceGroup.isValid())
    {
        if (!sourceGroup.data(Qt::EditRole).toString().contains(SPECIAL_GROUP_ID))
        {
            sourceGroup = sourceGroup.sibling(sourceGroup.row()+1, sourceGroup.column());
            continue;
        }

        QModelIndex sourceItem = sourceGroup.child(0, AbstractItem::NameData);
        while (sourceItem.isValid())
        {
            addMapping(sourceItem, createIndex(sourceItem.row(), NameField, sourceItem.internalPointer()));
            sourceItem = sourceItem.sibling(sourceItem.row()+1, sourceItem.column());
        }

        sourceGroup = sourceGroup.sibling(sourceGroup.row()+1, sourceGroup.column());
    }
}


